﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Lilium.Web.Mvc
{
	/// <summary>
	/// 
	/// </summary>
	/// <remarks>
	/// Thread Safety
	/// This type is thread safe.
	/// </remarks>
	public sealed class JavaScriptReference: ScriptResourceReferenceBase
	{
		public JavaScriptReference(string libraryName, string resourceName)
			: base(libraryName, resourceName)
		{
		}

		public override void Render(AjaxHelper ajaxHelper)
		{
			if (ajaxHelper == null)
				throw new ArgumentNullException("ajaxHelper");

			var scriptReferenceBuilder = new TagBuilder("script");
			scriptReferenceBuilder.MergeAttribute("type", "text/javascript");
			scriptReferenceBuilder.MergeAttribute("src", GetResourceVirtualPath());
			ajaxHelper.ViewContext.HttpContext.Response.Output.WriteLine(scriptReferenceBuilder.ToString(TagRenderMode.Normal));
		}
	}
}